import groovy.json.*
import org.apache.commons.lang.StringUtils
import redis.clients.jedis.*
import com.alibaba.moco.util.*
import com.alibaba.moco.*
import script.GlobalValues

/**
 * 模拟 滴滴 獲取城市ID
 * Created by wb-lj240895 on 2016/11/1.
 */
def excute(request){
    def slurper = new JsonSlurper()
    def params = request.getParameterMap();
    Jedis redis = RedisPoolInstance.getRedisClient()
    //欢行异常判断
    def e = redis.hget(GlobalValues.KEY_EXCEPTION,"cityId")
    if (!StringUtils.isBlank(e)) {
        def eJson = slurper.parseText(e)
        return eJson
    }
    CityIdPoiRequest req = BaseTypeUtil.mapToBean(params, CityIdPoiRequest.class) as CityIdPoiRequest
    String token = req.getAccess_token()
    System.out.println(token)
    if(token!=null) {//token!=null&&redis.exists(token)
        //redis.del(token)
        return slurper.parseText("{\"errno\":0,\"errmsg\":\"SUCCESS\",\"data\":{\"cityid\":5}}")
    }else{
        return slurper.parseText("{\"errno\":-1,\"errmsg\":\"token err cityid\",\"data\":null}")
    }


}

public class CityIdPoiRequest{
    String client_id    //	string	yes	申请应用时分配的APP_KEY
    String access_token //	string	yes	乘客认证信息
    double lat          //	float	yes	纬度
    double lng	        //  float	yes	经度
    String timestamp       //	int	yes	时间戳
    String sign         //	string	yes	签名
}
